﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DocumentFormat.OpenXml.Spreadsheet;

namespace OPENXMLLib
{
    class SharedFormulaSource
    {
        public uint SharedIndex { get; private set; }
        public string SourceCellReference { get; set; }
        public string SourceFormula { get; set; }
        public string SourceCellValue { get; set; }
        public bool HasError { get; set; }

        public const string ErrorValue = "#DIV/0!";

        public SharedFormulaSource(Cell formulaCell)
        {
            SourceCellReference = formulaCell.CellReference.Value;
            if (formulaCell.DataType != null && formulaCell.DataType == CellValues.Error)
            {
                HasError = true;
            }
            else
            {
                HasError = false;
            }

            SourceFormula = formulaCell.CellFormula.Text;

            SharedIndex = formulaCell.CellFormula.SharedIndex.Value;

            SourceCellValue = formulaCell.CellValue.Text;
        }
    }
}
